#include <reg52.h>
#include "Delay.h"
#include "LED_left.h"
#include "LED_right.h"

sbit key1=P3^1;
sbit key2=P3^0;
sbit key3=P3^2;
sbit key4=P3^3;


sbit LED = P2^2 ;

	int flag1=1;
  int flag2=1;
  int flag3=1;
  int flag4=1;
	
	
void key()
{
	
	if(key1==0)
	{	
		Delay(1);
		while(key1==0);
		Delay(1);
		flag1=~flag1;
	}
	if(key2==0)
	{	
		Delay(1);
		while(key2==0);
		Delay(1);
		flag2=~flag2;
	}
	if(key3==0)
	{	
		Delay(1);
		while(key3==0);
		Delay(1);
		flag3=~flag3;
	}
	if(key4==0)
	{	
		Delay(1);
		while(key4==0);
		Delay(1);
		flag4=~flag4;
	}
}


void main()
{

	LED_left(1);
	
	while(1)
  {
		key();

	  if(flag1==1)
	{
		LED=1;
	}
	else
	{
		LED_left(1);
		flag1=1;
	}
	if(flag2==1)
	{
		LED=1;
	}
	else
	{
		LED_left(2);
		flag2=1;
	}
	if(flag3==1)
	{
		LED=1;
	}
	else
	{
		LED_right(1);
		flag3=1;
	}
	if(flag4==1)
	{
		LED=1;
	}
	else
	{
		LED_right(2);
		flag4=1;
	}
  }
}